{extend name="layout:home" /}
{block name="container"}
<div class="layui-tab layui-tab-card">
    {include file="layout/admin_items" /}
    <!-- 操作说明 -->
    <div class="layui-tab-content page-tab-content" id="flexigrid">
        <div class="explanation" id="explanation">
            <div class="title" id="checkZoom">
                <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
                <span id="explanationZoom" title="收起提示" class="arrow"></span>
            </div>
            <ul>
                <li> 数据还原, 点击恢复选项进行数据库导入.</li>
                <li> 导入的SQL文件语句必须按照MYSQL的语法编写</li>
            </ul>
        </div>

        <div class="mDiv">
            <div class="ftitle">
                <div style="width: 100px;float: left;line-height: 56px;"><h3>sql文件列表</h3></div>
                <div style="width: 300px;float: left;line-height: 56px;"><h5>(备份文件数量：{$filenum}，占空间大小：{$total|format_bytes})</h5></div>
            </div>
            <div title="刷新数据" class="pReload"><i class="fa fa-refresh"></i></div>
        </div>
        <table class="layui-table lay-even">
            <colgroup>
                <col width="150">
                <col width="200">
                <col width="200">
                <col>
                <col width="150">
            </colgroup>
            <thead>
            <tr>
                <th align="left" abbr="article_title" axis="col3" class="">
                    <div style="text-align: left; width: 200px;" class="">文件名称</div>
                </th>
                <th align="center" abbr="ac_id" axis="col4" class="">
                    <div style="text-align: center; width: 50px;" class="">卷号</div>
                </th>
                <th align="center" abbr="article_show" axis="col5" class="">
                    <div style="text-align: center; width: 50px;" class="">压缩</div>
                </th>
                <th align="center" abbr="article_time" axis="col6" class="">
                    <div style="text-align: center; width: 150px;" class="">数据大小</div>
                </th>
                <th align="center" abbr="article_show" axis="col7" class="">
                    <div style="text-align: center; width: 150px;" class="">备份时间</div>
                </th>
                <th align="center" abbr="article_show" axis="col8" class="">
                    <div style="text-align: center; width: 130px;" class="">状态</div>
                </th>
                <th align="center" axis="col1" class="handle">
                    <div style="text-align: center; width: 250px;">操作</div>
                </th>
            </tr>
            </thead>
            <tbody>
            {notempty name="list"}
            {volist name="list" id="vo"}
            <tr>
                <td align="left" class="">
                    <div style="text-align: left; width: 200px;">{$vo.basename}</div>
                </td>
                <td align="center" class="">
                    <div style="text-align: center; width: 50px;">{$vo.part}</div>
                </td>
                <td align="center" class="">
                    <div style="text-align: center; width: 50px;">{$vo.compress}</div>
                </td>
                <td align="center" class="">
                    <div style="text-align: center; width: 150px;">{$vo.size|format_bytes}</div>
                </td>
                <td align="center" class="">
                    <div style="text-align: center; width: 150px;">{$vo.time|date="Y-m-d H:i:s"}</div>
                </td>
                <td align="center" class="">
                    <div style="text-align: center; width: 130px;">-</div>
                </td>
                <td align="center" class="handle">
                    <div style="text-align: center; width: 170px; max-width:170px;">
                        <a value="{:url('/admin/Database/import',['time'=>$vo.time])}" href="javascript:void(0)" class="db-import"><i
                                class="fa fa-repeat"></i>恢复</a> |
                        <a href="{:url('/admin/Database/downFile',['time'=>$vo.time])}"><i class="fa fa-download"></i>下载</a> |
                        <a href="{:url('/admin/Database/del',['time'=>$vo.time])}"><i class="fa fa-trash"></i>删除</a>
                    </div>
                </td>
            </tr>
            {/volist}
            {else}
            <tr class="no_data">
                <td colspan="11">{$Think.lang.ds_no_record}</td>
            </tr>
            {/notempty}
            </tbody>
        </table>
    </div>
</div>
<script>

    $(document).ready(function () {
        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function () {
            $(this).toggleClass('trSelected');
        });

        // 点击刷新数据
        $('.fa-refresh').click(function () {
            location.href = location.href;
        });
    });

    $(".db-import").click(function () {

        var self = this, status = ".";
        $.get($(this).attr('value'), success, "json");
        window.onbeforeunload = function () {
            return "正在还原数据库，请不要关闭！"
        }
        function success(data) {
            if (data.code) {
                if (data.gz) {
                    data.info += status;
                    if (status.length === 5) {
                        status = ".";
                    } else {
                        status += ".";
                    }
                }
                $(self).parent().parent().prev().find('div').text(data.msg);
                if (data.data) {
                    $.get($('.db-import').attr('value'), {"part": data.data.part, "start": data.data.start}, success, "json");
                } else {
                    window.onbeforeunload = function () {
                        return null;
                    }
                }
            } else {
                layer.alert(data.msg, {icon: 2});
            }
        }
    });
</script>
{/block}

    